C++ Tutorial: Day 3
h
HahaYes (1284)

EDIT: Day 4 Is TOTALLY not DElaYeD

Day 3: Conditionals and Headers

Thank you to.....

IF SOMEONE WOULD HELP ME EXPLAIN EVERY SINGLE HEADER PLEASE CONTACT ME IN THE COMMENTS BELOW

@DynamicSquid for header emphasize

@awesome10 wanted conditionals.


A emphasize on Headers

I realized I never really went in deep with headers in C++, so here is a bunch of headers that you need or want.

Literally just use #include <bits/stdc++.h> to avoid the hassle. It has every single header that you need all in one.

Day 3!

Conditionals

What are conditionals?

Conditionals are expressions that evaulate to either true or false. They are usually used for if, else, and while loops.

If Statements

If statements are used to execute code only if the condition is true.
If the statement is false, the expression is just ignored, and the program will continue to run.

Example:

int x = 8;
int y = 5
if (x < y) {
	cout << "x might be greater than y";
}

Else Statements

Else statements are the opposite of a if statement. Else statements will only be runned(ran? someone tell me what it is.) if the condition is FALSE

Example:

int x = 5;
int y = 8;
if (x < y) {
	cout << "X is greater than y." << endl;

} else{
	cout << "Y is greater than X." << endl;

}

Explanation: y is greater than x, so that must mean that the if statement is false. Therefore, the program would move on to the else condition and print "Y is greater than X"
(Do you guys need else if?)

While Loop Statements

Loops (can) execute a block of code as long there is a condition that is specified.
Loops are awesome because they make your code look cleaner. (my code is not clean btw)

While loops only loop through a block o code as long as a specified condition is true:
Example:

int i = 0;
while (i < 10) {
	cout << i << "\n";
	i++;

}

This program will loop over and over again as long as the variable i is less than 10.

That's it!

Upvote?

Thanks for 400 cycles guys

Credits:
w3schools.com
sololearn.com

Featured Shoutout....
@Muffinlavania

Featured Shoutout....
@DyanamicSquid for all my shoutouts.

If there are any bugs or typos, please feel free to tell me.

Honk Honk YES! @DannyIsCoding (totally not stolen from me)
You are viewing a single comment. View All
DungeonMaster00 (164)

Header Files

One way to make your code more organized and neat.

Header files are as cool and handy as heck.

A header file is a C++ file which you can use import in a header

A C++ header file's file extention is .hpp.

Make a file with the .hpp file extension and write your C++ code in there.

To use your C++ header file use #include "headerfilename.hpp", of course, replacing headerfilename with the name of your header file.

Voila! Now you know what header files are and how to use them.

BTW there are also C header files. In case you were wondering.

HahaYes (1284)

@nk1rwc yes, will continue this series :)