0

While Loop

Does the while loop only work with int variables? Thanks beforehand for the answer:)

14th Mar 2017, 5:04 AM
Mira Pauli
3 odpowiedzi
0
No, while loop working while condition is true. The type of the variables can be the type you want. for example --- string a = "aab"; while (a != "aaa") { //change your a-variable to "aaa" and program will quit from loop. }
14th Mar 2017, 5:16 AM
Tony Loa
Tony  Loa - avatar
+ 1
As Tony Loa explained, while looks for the condition to be true. So you can do While loops with: bool, int, double, float, byte, etc. Yet with a string (imagine that the user should input an exact phrase an the program ask until it as been changed: "continue? y" if "n" or another exit)
14th Mar 2017, 12:50 PM
Michael Ceballos Paulino
Michael Ceballos Paulino - avatar
0
well if you want to be literal, while loop only works with boolean variables :p
14th Mar 2017, 10:41 AM
William La Flamme
William La Flamme - avatar