+ 10

I still don't understand how programming work?

I am stress with Swift loop, Python loop and stuff... the ++ and -- sign is so confusing

15th Oct 2019, 2:43 AM
Kiman Heng
Kiman Heng - avatar
37 Answers
+ 24
Duplicate IT ++ means "keep adding" while -- means "keep subtracting" Therefore, if i = 1, And we want to keep adding 1, then we'll say, i++ i becomes 2 [i.e. i = 2] i ++ again i will now become 3 [i.e. i = 3] And that's how it goes on... If we want to add 3, It will be: i += 3 (or i = i + 3) So if i = 0; And we say, i += 3, then i will be 0 + 3 which is 3. i += 3 again ...will give you 3 + 3 = 6. i += 3 again ...will give you 6 + 3 = 9. i += 3 again ...will give you 9 + 3 = 12. And it keeps going that way forever...
15th Oct 2019, 10:52 AM
Makzo
Makzo - avatar
+ 8
++ is used to increase/increment the value of a variable by 1. In other words, it adds 1 to the variable. -- subtracts 1 from a variable. Loops are used for repetition.
15th Oct 2019, 3:08 AM
Sonic
Sonic - avatar
+ 5
V F Yes, it is the same in JS and many other OOP languages like Python, etc.
15th Oct 2019, 12:32 PM
Makzo
Makzo - avatar
+ 4
Please note that ++ and -- are not available in Python. Edit: oh I realise you may be using Swift.
15th Oct 2019, 3:14 AM
Sonic
Sonic - avatar
15th Oct 2019, 1:24 PM
Makzo
Makzo - avatar
+ 4
Operators 1. ++ increment 2. -- decrement There are two types of increment(++) and decrement(--) operator : - (i) pre increment (ii) post increment (i) pre increment increment the values first then assign to variable. Ex: - int i =7; System.out.println(++i); // printing the variable in java O/p - 8 Here, i is incremented first by 1 and then printed so became 8 Pre Decrement System.out.println(--i); // printing the variable in java O/p - 6 Here, i is Decremented first by 1 and then printed so became 6 (ii) Post Increment is assign tge value to variable first then incremented by 1. Ex:- int i=7; System.out.println(i++); // printing statement in java O/p - 7 Here, i is printed first then assigned to variable i if we print i variable again it will print 8. Post decrement assign the value first then decremented by 1 same as post increment Ex :- int i = 8; System.out.println(i--); O/p - 8 Here, variable i printed first then incremented On printing i again System.out.println(i); o/p- 9
15th Oct 2019, 6:10 PM
Guddu Kumar
Guddu Kumar - avatar
+ 4
Hopefully, by now you understand 😊
16th Oct 2019, 10:04 PM
Sonic
Sonic - avatar
+ 4
👑Duplicate IT💫⚘🌚 (Storm Me) I can understand your problem. You are unable to understand how programming work, it means there is something wrong with your C basics. You can improve it by first clearing the basics of C and then moving to other programming languages.
22nd Oct 2019, 7:24 AM
Raman Singh
+ 3
++ increases the value by 1 and not by 2.
15th Oct 2019, 3:15 AM
Sonic
Sonic - avatar
+ 3
15th Oct 2019, 3:16 AM
Sonic
Sonic - avatar
+ 3
Those are binary operators requiring two operands e.g. a and b. a=1 b=2 print(a+b) # gives 3 print(a-b) # gives -1
15th Oct 2019, 3:18 AM
Sonic
Sonic - avatar
+ 3
i+=3 is the same as saying i=i+3.
15th Oct 2019, 3:22 AM
Sonic
Sonic - avatar
+ 3
BTW, when using i+=3, note that the operator is += and not just +
15th Oct 2019, 3:23 AM
Sonic
Sonic - avatar
+ 3
It will be 3 more than what it was before the statement.
15th Oct 2019, 5:27 AM
Sonic
Sonic - avatar
+ 3
Just read it all slowly again
15th Oct 2019, 7:10 AM
ALCapone_1867
ALCapone_1867 - avatar
+ 3
At start it will seem little bit confusing, but when you start praticing you will start to understand the concept behind it and then you can talk with your computer.
15th Oct 2019, 7:42 PM
Raj Ghosh
Raj Ghosh - avatar
+ 2
Sonic so what is single plus? + or -
15th Oct 2019, 3:16 AM
Kiman Heng
Kiman Heng - avatar
+ 2
Sonic where did u see the +i or i+ Like i+ = 3, i dont remember, but it like that Can you explain?
15th Oct 2019, 3:21 AM
Kiman Heng
Kiman Heng - avatar
+ 2
Sonic so what is the value of i, if i = i+3😂
15th Oct 2019, 3:26 AM
Kiman Heng
Kiman Heng - avatar
15th Oct 2019, 6:11 PM
Guddu Kumar
Guddu Kumar - avatar