+ 1
Double in for loop
Hello guys I am loving the lessons so far. I got a quick question. can i use double variables while running a for loop? I noticed only Int was used through the lessons. example for(double x=1.3; x<= 22.8; x++){ System.out,println(x); } thank you.
3 odpowiedzi
+ 2
Yes of course.Here is the evidence
https://code.sololearn.com/c8BTmUV4xC3m/?ref=app
+ 4
Floating type value is uncertain, in that they have fractal part. So verifying a variable value equals another variable/value can be tricky. Other than that, integers operation requires less CPU cycle (read: faster) compared to floating point types operation.
Hth, cmiiw
+ 1
Practically you can, but I'm not sure it has any meaningful uses, plus it can be hard to determine how many times will it get executed