Question

In: Computer Science

I'm in a intro to programming class using C++. In some examples in my book, they...

I'm in a intro to programming class using C++. In some examples in my book, they use the letter ' i ' to do certain things like a 'for loop'. I was looking around the internet and I can't seem to find what that specific letter does. In all the websites I went to about operators it wasn't listed. Do I need to define it? Or just use it like it is?

Example: for(int i = 0; i < 4; i++)

Solutions

Expert Solution

Here, in the case of for loop or in particular any other case, the letter 'i' is just used as a variable always. It has no relevance specifically and isn't any type of keyword /operator to be particular. Just as generally we declare any variable before using it in C++, we declare the 'i' variable also. Although, there isn't any requirement of defining the variable and assigning value to it beforehand and then using it elsewhere. We can simply declare a variable and assign value to it later on as well. The role of the letter 'i' or any other variable as a whole is to just store the assigned data and use it when called or required. So, for instance, here, we can normally declare the variable I before using it in for loop or anywhere else by using the statement int i and then using it in For(i=0;i<4;i++). We can even declare the variable 'i' inside the for loop itself, for example  in for(int i=0;i<4;i++), It doesn't make much difference. So, to be precise, in programming in C++ language we have to follow a golden rule of declaring the variable and then using it somewhere blindly. Nothing else matters beyond that i.e. we can declare the variable wherever and we can define it wherever and whenever we want after its declaration.

Hope this helps:). If you still have any doubt, feel free to ask it out in the comment section.


Related Solutions

This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's...
This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's and JSP 3rd Edition. I need help modifying some code. I will post the code I was told to open that needs to be modified below. In this exercise, you'll enhance the Future Value application to store the amount and interest rate in the user's session. That way, the user can experiment with different numbers of years to see the value of his or...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get...
C++ programming interest using for loops. I'm fairly new to C++ programming. I really don't get for loops, and wanted help with this question. How do I go about it? 1a. Write a program to ask the user for the starting balance of their savings account, what interest rate they are earning, and how many years they are planning to keep the account open. To calculate the new balance, including compounded interest: use a for loop to loop through the...
I have a quick question about this C ++ problem in my intro class. I have...
I have a quick question about this C ++ problem in my intro class. I have been able to get the first answer consistently when I test it, but my second seems to either be high or low no matter how I change it. Can you show me how you would do this problem with the setprecision(2) Paula and Danny want to plant evergreen trees along the back side of their yard. They do not want to have an excessive...
I'm using livesql for my database class to try and do these A medical clinic has...
I'm using livesql for my database class to try and do these A medical clinic has doctors, along with patients assigned to one of the doctors. Create 2 tables that include fields below with primary key chosen below. Use appropriate data types and simplified field names, eg: - Doctor’s Table: DKey ID           Last name First name Home phone Medical specialty Monthly Salary Patient’s Table: PKey ID           Last name First name Address (Use Address as column name)...
Intro To Programming In Java(2nd Edition) I'm currently trying to study and understand stuff better, but...
Intro To Programming In Java(2nd Edition) I'm currently trying to study and understand stuff better, but I need some help. Can someone please help me define/understand the following: Section 2.1 -Static Methods -Control Flow - Input Parameters and Arguments (single and multiple) -Overloading -Return Statement -Side Effects -Scope and Lifetime -Pass-by-Value (Primitives) vs Pass-by-Reference (Arrays) -Reason of Use: Organize Code Section 3.1 -Strings (substring, charAt, split, indexOf, contains, length, and == vs equals) -Constructor -Instance Methods -Reference types(String and Arrays)...
This is for Javascript programming language: A. Class and Constructor Creation Book Class Create a constructor...
This is for Javascript programming language: A. Class and Constructor Creation Book Class Create a constructor function or ES6 class for a Book object. The Book object should store the following data in attributes: title and author. Library Class Create a constructor function or ES6 class for a Library object that will be used with the Book class. The Library object should be able to internally keep an array of Book objects. B. Methods to add Library Class The class...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I'm having trouble programming connect four board game using linked lists, sets and maps in c++....
I'm having trouble programming connect four board game using linked lists, sets and maps in c++. Can you code connect four game using these concepts.
Here is an outline for some code I need to write. This class used Intro to...
Here is an outline for some code I need to write. This class used Intro to Java Edition 11, and we only got to Chapter 9. There is no set right way that this program has to be done. Feel free to interpret this in a way that you wish. Mrs. Quackenbush is back! She now has bought a beverage establishment, The Green Dragon Inn, and needs to have a way to insure the consistency of the drinks her employees...
Hi guys, I'm working on an assignment for my Java II class and the narrative for...
Hi guys, I'm working on an assignment for my Java II class and the narrative for this week's program has me a bit lost. I've put the narrative of the assignment in the quotation marks below. " Included with this assignment is an encrypted text file. A simple Caesar cipher was used to encrypt the data. You are to create a program which will look at the frequency analysis of the letters (upper and lowercase) to help “crack” the code...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT