FORUMS
Remove All Ads from XDA

[GUIDE]**Beginners guide to programming-C,C++,Bash,Python,java**[GUIDE]

250 posts
Thanks Meter: 1,006
 
By Dark Wraith, Senior Member on 26th December 2013, 11:59 AM
Post Reply Email Thread
29th December 2013, 08:13 AM |#21  
Dark Wraith's Avatar
OP Senior Member
Flag Bangalore
Thanks Meter: 1,006
 
Donate to Me
More
Quote:
Originally Posted by karan5chaos

"if .. else" conditions is usually taught with "switch" conditions.

switch conditions are better then nested "if..else" and "else.. if" conditions as it doesn't needs to perform all the conditions check like if..else .
u should consider including "switch" in tutorial if u can

ummm....sure...will add switch statement as well......
29th December 2013, 08:36 AM |#22  
N00B_IN_N33D's Avatar
Senior Member
Flag Pompano Beach
Thanks Meter: 999
 
More
Quote:

Yes..you are correct..If....else is a conditional statement...and a conditional statement can be used as a loop...

Code:
int i=0;

if( i <= 50)
{

printf("Hello");

i++;

}
would print hello 50 times....

I'm not too sure about that.. I've never messed with C before, however, I can't imagine the logic being different than Java or C++. Assuming it is similar, your above would only execute the printf statement once.

To be exact, the integer i would be set to 0, then the condition would be checked (0 <= 50 equates to true), the printf statement would be executed and i would be incremented by 1. After that, the program would end/exit the if statement and terminate. However, had the "if" been replaced with a "while" the code would execute as desired..

Could be wrong though.

Sent from my Nexus 4 using Tapatalk
29th December 2013, 10:09 AM |#23  
Dark Wraith's Avatar
OP Senior Member
Flag Bangalore
Thanks Meter: 1,006
 
Donate to Me
More
Quote:
Originally Posted by N00B_IN_N33D

I'm not too sure about that.. I've never messed with C before, however, I can't imagine the logic being different than Java or C++. Assuming it is similar, your above would only execute the printf statement once.

To be exact, the integer i would be set to 0, then the condition would be checked (0 <= 50 equates to true), the printf statement would be executed and i would be incremented by 1. After that, the program would end/exit the if statement and terminate. However, had the "if" been replaced with a "while" the code would execute as desired..

Could be wrong though.

Sent from my Nexus 4 using Tapatalk

yes....you are totally right..it will print it just once....no idea what i was thinking

(thats why i should never post after just waking up from sleep)

thanks for the post buddy...I will update the op....
The Following User Says Thank You to Dark Wraith For This Useful Post: [ View ] Gift Dark Wraith Ad-Free
29th December 2013, 12:16 PM |#24  
abcdjdj's Avatar
Senior Member
Flag Thane
Thanks Meter: 3,254
 
More
Nice work bro
Btw don't you think that it would be better to use // for comments in all the C snippets rather than # as it will confuse beginners between comments and the preprocessor (#). Also, assigning ints to chars is allowed (at least in Java you can directly assign any value between 0-65535). In C it seems that you can assign upto 255 without type casting. Also, the keyword is class and not Class and the s in string is in upper case.

Please don't get offended or anything, I have no intention of pointing out mistakes. It's just that new comers and beginners should not familiarize themselves with misconceptions. Excellent initiative bro. Keep it up
29th December 2013, 12:52 PM |#25  
Dark Wraith's Avatar
OP Senior Member
Flag Bangalore
Thanks Meter: 1,006
 
Donate to Me
More
Quote:
Originally Posted by abcdjdj

Nice work bro
Btw don't you think that it would be better to use // for comments in all the C snippets rather than # as it will confuse beginners between comments and the preprocessor (#). Also, assigning ints to chars is allowed (at least in Java you can directly assign any value between 0-65535). In C it seems that you can assign upto 255 without type casting. Also, the keyword is class and not Class and the s in string is in upper case.

Please don't get offended or anything, I have no intention of pointing out mistakes. It's just that new comers and beginners should not familiarize themselves with misconceptions. Excellent initiative bro. Keep it up

Yes you are correct.. Just that I had forgotten the // for commenting in C..been working on my tool which is in bash and got the bad habit of commenting everything with #..as for the assigning from char to into...I chose a bad example..I have to include a topic on type casting... and yes I am making a list of changes that needs to be made to the op... Will do so in a few hours... And of course m not offended..its a good thing you are pointing out mistakes.. Feedbacks help streamline the guide until it is 100% correct

Sent from my LegoIce_Fusion™ using xda app-developers app
29th December 2013, 02:59 PM |#26  
abcdjdj's Avatar
Senior Member
Flag Thane
Thanks Meter: 3,254
 
More
Quote:
Originally Posted by Dark Wraith

Yes you are correct.. Just that I had forgotten the // for commenting in C..been working on my tool which is in bash and got the bad habit of commenting everything with #..as for the assigning from char to into...I chose a bad example..I have to include a topic on type casting... and yes I am making a list of changes that needs to be made to the op... Will do so in a few hours... And of course m not offended..its a good thing you are pointing out mistakes.. Feedbacks help streamline the guide until it is 100% correct

Sent from my LegoIce_Fusion™ using xda app-developers app

Afaik, declaring an array without giving the size results in a syntax error. In Java as well as C..
29th December 2013, 02:59 PM |#27  
xacobe97's Avatar
Member
Flag Vigo, Galicia
Thanks Meter: 5
 
More
Nice job! Now i'm gonna learn C, looks difficult, but very nice
29th December 2013, 03:28 PM |#28  
klincharov's Avatar
Senior Member
Flag Wien/Sofia
Thanks Meter: 22
 
More
Can we get some noob explanation on what exactly is a device tree ?

Otherwise awesome post(s), although it makes me sad - I understand the concepts of programming, but don't seem to be suitable to be a programmer !
29th December 2013, 03:30 PM |#29  
Senior Member
Thanks Meter: 198
 
More
if...else just isn't a loop. and it can't be used as a loop. theres no iteration in an if...else statement. you can perform it within a loop but then an if...else statement is still not a loop but the loop in which the statement is is the loop.
29th December 2013, 03:39 PM |#30  
Dark Wraith's Avatar
OP Senior Member
Flag Bangalore
Thanks Meter: 1,006
 
Donate to Me
More
Quote:
Originally Posted by abcdjdj

Afaik, declaring an array without giving the size results in a syntax error. In Java as well as C..

Yeah...correct again....i have made the changes and edited the op........
29th December 2013, 03:50 PM |#31  
J-Hope's Avatar
Member
Thanks Meter: 11
 
More
Quote:
Originally Posted by N00B_IN_N33D

I'm not too sure about that.. I've never messed with C before, however, I can't imagine the logic being different than Java or C++. Assuming it is similar, your above would only execute the printf statement once.

To be exact, the integer i would be set to 0, then the condition would be checked (0 <= 50 equates to true), the printf statement would be executed and i would be incremented by 1. After that, the program would end/exit the if statement and terminate. However, had the "if" been replaced with a "while" the code would execute as desired..

Could be wrong though.

Sent from my Nexus 4 using Tapatalk

Not to be too precise or pedant, but I am pretty sure that since you inizialized i=0 the condition "i<=50" in the while would printf 51 values and not 50 (even if the last one would be 50).

ie: 0, 1, 2, 3, 4, 5....50.
Post Reply Subscribe to Thread

Tags
c++, java, programming guide, python, tutorial

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes