2️⃣

2.2 Breaking out of the main method

Every program has the “main method”. It’s where the bulk of your code goes, if not all of it. What do you do if you have a chunk of code that you want to repeat multiple times? To eliminate repetitiveness, we use methods.
 
Methods have similar syntax to the main method. You begin with the data type, then the method name, then finally, the parameter(s), if applicable.
int main(){ //code } datatype var-name (parameters){ //code }
 
To declare the function, simply type out the first line of it, and if you would like, add in your own parameters.
datatype var-name (parameters); int main(){ //code } datatype var-name (parameters){ //code }

Previous Section

Next Section

 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.