How can I make 2 different operations with the same values? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I make 2 different operations with the same values?

For example introduce 5 then 5 and finally I obtain 5+5=10 and 5-5=0

23rd Jan 2020, 4:39 AM
Carlos Flores
Carlos Flores - avatar
1 Answer
+ 3
You can use a loop to do this. Let's say the loop goes from 0 to 1 (2 iterations); you then place a check in the loop body (e.g. using `if` statement), if loop counter equals 0 you add the two numbers, if it was 1, you subtract the two numbers instead.
23rd Jan 2020, 5:58 AM
Ipang