Answered by:
For...EndFor
Question

Steps involved in finding the square of even numbers from 15 to 30.Sunday, August 21, 2016 2:58 PM
Answers

... in SmallBasic:
For n = 15 To 30
If Math.Remainder(n,2) = 0 Then
TextWindow.WriteLine(n +"² = "+ n * n)
EndIf
EndFor
TextWindow.WriteLine("") Marked as answer by litdev Sunday, August 28, 2016 9:19 AM
Sunday, August 21, 2016 3:15 PMAnswerer 
Yes, see my answer.
For n = 16 to 30 step 2
TextWindow.WriteLine(n +"² = "+ n * n)
EndFor
Jan [ WhTurner ] The Netherlands
 Edited by WhTurner33Editor Sunday, August 21, 2016 4:03 PM
 Proposed as answer by Nonki Takahashi Monday, August 22, 2016 2:30 AM
 Marked as answer by litdev Sunday, August 28, 2016 9:18 AM
Sunday, August 21, 2016 4:02 PMAnswerer 
PS:
If you want to use 'Step 2' in the ForTo loop and want to be on the save side, weather to start from 15 or 16, you should use a small modificaion
n1 = 15 ' 16 n2 = 30 n1 = 2 * Math.Round((n1+1) / 2) '' > n1 if even OR next even number For n = n1 To n2 Step 2 TextWindow.WriteLine(n +"² = "+ n * n) EndFor TextWindow.WriteLine("")
where it does'nt matter if you start from 15 or 16, and covers oth cases.
 Marked as answer by litdev Sunday, August 28, 2016 9:18 AM
Monday, August 22, 2016 4:42 PMAnswerer
All replies

... in SmallBasic:
For n = 15 To 30
If Math.Remainder(n,2) = 0 Then
TextWindow.WriteLine(n +"² = "+ n * n)
EndIf
EndFor
TextWindow.WriteLine("") Marked as answer by litdev Sunday, August 28, 2016 9:19 AM
Sunday, August 21, 2016 3:15 PMAnswerer 
Better:
For n = 16 to 30 step 2
The If ... Endif can then be left out.
Jan [ WhTurner ] The Netherlands
 Proposed as answer by Nonki Takahashi Monday, August 22, 2016 2:30 AM
Sunday, August 21, 2016 3:26 PMAnswerer 
Thanks. But I have not learnt Math.Remainder function. Can it be solved without using this?
Regards
Sunday, August 21, 2016 3:37 PM 
Yes, see my answer.
For n = 16 to 30 step 2
TextWindow.WriteLine(n +"² = "+ n * n)
EndFor
Jan [ WhTurner ] The Netherlands
 Edited by WhTurner33Editor Sunday, August 21, 2016 4:03 PM
 Proposed as answer by Nonki Takahashi Monday, August 22, 2016 2:30 AM
 Marked as answer by litdev Sunday, August 28, 2016 9:18 AM
Sunday, August 21, 2016 4:02 PMAnswerer 
If Math.Remainder(n,2) = 0 Then
... is the same as ...
If n/2 = Math.Round(n/2) Then ' or
If n/2 = Math.Floor(n/2) Then
and means that 'If the current number is divisible by 2 without rest' ... so is a even number.
So, if you have to begin with 15, you can also use
For n = 15 To 30
If n/2 = Math.Round(n/2) Then ' If Math.Remainder(n,2) = 0 Then
TextWindow.WriteLine(n +"² = "+ n * n)
EndIf
EndFor
 Edited by Pappa LapubEditor Sunday, August 21, 2016 4:30 PM
Sunday, August 21, 2016 4:25 PMAnswerer 
my variation:
CUBE of numbers 1 to 100
For n = 1 To 100 Step 3
TextWindow.Write (" cube of " + n + " = " + n*n*n)
TextWindow.WriteLine ("") ' linefeed
EndForSunday, August 21, 2016 6:53 PMAnswerer 
PS:
If you want to use 'Step 2' in the ForTo loop and want to be on the save side, weather to start from 15 or 16, you should use a small modificaion
n1 = 15 ' 16 n2 = 30 n1 = 2 * Math.Round((n1+1) / 2) '' > n1 if even OR next even number For n = n1 To n2 Step 2 TextWindow.WriteLine(n +"² = "+ n * n) EndFor TextWindow.WriteLine("")
where it does'nt matter if you start from 15 or 16, and covers oth cases.
 Marked as answer by litdev Sunday, August 28, 2016 9:18 AM
Monday, August 22, 2016 4:42 PMAnswerer