if trueFalseExpn then
statementsAndDeclarations
{ elsif trueFalseExpn then
statementsAndDeclarations }
[ else
statementsAndDeclarations ]
end if
So inside of an ifStatement you can have any statementsAndDeclarations, which includes other ifStatement.
Oh whoops, idk what happended with me at that time... idk why I didn't look at it lol. Thanks though, that answers a hell lot
Sponsor Sponsor
Raknarg
Posted: Sat Mar 02, 2013 10:02 pm Post subject: RE:Help for if statements
It's called nesting, which you can do with basically any structure. A loop within a loop, if within an if, for within a for, and such.
storm2713687
Posted: Sat Mar 02, 2013 10:06 pm Post subject: Re: RE:Help for if statements
Raknarg @ Sat Mar 02, 2013 10:02 pm wrote:
It's called nesting, which you can do with basically any structure. A loop within a loop, if within an if, for within a for, and such.
Do I have to add a certain code to my program or will it work if I just use an if within an if?
Raknarg
Posted: Sat Mar 02, 2013 10:12 pm Post subject: Re: Help for if statements
Turing:
var x :int:=14
if x mod2=0then if x >= 10then put"This is an even number greater or equal to ten." else put"This is an even number less than ten." endif else if x > 10then put"This is an odd number greater than ten." else put"This is an odd number less than ten." endif endif
try running that.
storm2713687
Posted: Sun Mar 03, 2013 8:39 pm Post subject: Re: Help for if statements
Raknarg @ Sat Mar 02, 2013 10:12 pm wrote:
Turing:
var x :int:=14
if x mod2=0then if x >= 10then put"This is an even number greater or equal to ten." else put"This is an even number less than ten." endif else if x > 10then put"This is an odd number greater than ten." else put"This is an odd number less than ten." endif endif
try running that.
Thanks for helping, but what does mod do after the "if" statement at the top? Sorry, I'm so bad at this
Dreadnought
Posted: Sun Mar 03, 2013 9:12 pm Post subject: Re: Help for if statements
It's just a positive remainder from integer division. Basically, "x mod 2" will return 1 if x is an odd number and 0 if x is an even number.
Raknarg
Posted: Mon Mar 04, 2013 12:46 pm Post subject: RE:Help for if statements
Or if I was looking at an angle, for instance, and wanted to have it only between 0 and 359. Then lets say I had an angle of 450.
450 mod 360 = 90
Divides the left number by the right one, then returns whatever the remainder is.
storm2713687
Posted: Mon Mar 04, 2013 8:12 pm Post subject: Re: Help for if statements
I'm confused
So is mod supposed to be division?
Sponsor Sponsor
Insectoid
Posted: Mon Mar 04, 2013 8:21 pm Post subject: RE:Help for if statements
Mod returns the remainder of a division. 10/3 = 3, with a remainder of 1. 10 mod 3 = 1.
The way to check if a number is odd or even is to divide it by 2 and take the remainder. If the remainder is 0, then it's even. If the remainder is 1, then it's even. 5/2 = 2, with a remainder of 1. 5 mod 2 = 1, therefor 5 is odd. 4/2 = 2, with a remainder of 0. 4 mod 2 = 0.
storm2713687
Posted: Tue Mar 05, 2013 11:49 am Post subject: Re: RE:Help for if statements
Insectoid @ Mon Mar 04, 2013 8:21 pm wrote:
Mod returns the remainder of a division. 10/3 = 3, with a remainder of 1. 10 mod 3 = 1.
The way to check if a number is odd or even is to divide it by 2 and take the remainder. If the remainder is 0, then it's even. If the remainder is 1, then it's even. 5/2 = 2, with a remainder of 1. 5 mod 2 = 1, therefor 5 is odd. 4/2 = 2, with a remainder of 0. 4 mod 2 = 0.
I still don't really get it... isn't 10/3 supposed to be like 3.something?
DemonWasp
Posted: Tue Mar 05, 2013 1:22 pm Post subject: RE:Help for if statements
If you divide 10 solid objects (each indivisible) into 3 even piles, then each pile has 3 objects in it and you have one left over (the remainder).
10 div 3 will give you 3, the number of objects in each pile.
10 mod 3 will give you 1, the number of objects left over.
storm2713687
Posted: Tue Mar 05, 2013 1:24 pm Post subject: Re: RE:Help for if statements
DemonWasp @ Tue Mar 05, 2013 1:22 pm wrote:
If you divide 10 solid objects (each indivisible) into 3 even piles, then each pile has 3 objects in it and you have one left over (the remainder).
10 div 3 will give you 3, the number of objects in each pile.
10 mod 3 will give you 1, the number of objects left over.
Ohhh I get it now, thanks
Is mod supposed to be some kinda simple math thing?
DemonWasp
Posted: Tue Mar 05, 2013 2:11 pm Post subject: RE:Help for if statements
mod stands for "modulus", which basically means "divide evenly and find the remainder".
This leads to a kind of mathematics called "modular arithmetic". It sounds scary, but the hours in a day follow the same basic rules: hours start at 1, count up to 12, then return to 1 again. But! The next number after 12 is 13, and 13 mod 12 = 1. And, the hour after that, hour #14, is normally called "2pm", but notice that 14 mod 12 = 2. For more detail, see http://en.wikipedia.org/wiki/Modular_arithmetic . There's a discussion of modular arithmetic in a first-year university class, usually called "Classical Algebra" or similar.
Note: Hours don't follow exactly the same system, because 12 mod 12 = 0 (you can divide 12 objects into 12 even piles with 0 left over). However, the idea is the same, just offset by one. The hour "12am midnight" can be thought of as 0, and the hour "1am" thought of as 1. Then "11am" is 11, and "12pm noon" is 0 (because 12 mod 12 = 0).