Double in for loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

19th Jul 2019, 4:05 PM
DEEDEE ENESHAH
DEEDEE ENESHAH - avatar
3 Answers
+ 2
Yes of course.Here is the evidence https://code.sololearn.com/c8BTmUV4xC3m/?ref=app
19th Jul 2019, 4:42 PM
Highman
Highman - avatar
+ 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
20th Jul 2019, 4:29 AM
Ipang
+ 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
19th Jul 2019, 4:12 PM
Agent_I
Agent_I - avatar