Q:

Beginner C loop function

I just started venturing into C coming from PHP. I'm having trouble with the printf() function when its called from within another function:
#include <stdio.h>

void printloop (int valx) {
    int x;
    for (x = valx; x < 5; x++) {
        printf("Value of x is: %d\n", x);
    }
}

int main() {
    printloop(5);
    return 0;
}

The program will compile and run but there is no output on screen.

A:

When you invoke the printloop function with 5 the for loop essentially becomes
for (x = 5; x < 5; x++) {
    //...
}

And x < 5 will never be true.

I guess what you meant was something like 
for (x = 0; x < valx; x++) {
    //...
}

A:

What's wrong here is that your logic is saying 5 < 5, which is false.  Your for loop is not executing because when your printloop function is invoked at  printloop(5); it is passing the integer value of 5.
void printloop (int valx) {
int x;
for (x = valx; x < 5; x++) {
    printf("Value of x is: %d\n", x);
}

Your printloop function is receiving a value of 5, setting x inside of your function to x = 5.
When it is time for your for loop to execute you will have
void printloop (int valx) {
    int x = 5;
    for (5 = valx; 5 < 5; 5++) {
        printf("Value of x is: %d\n", x);
    }
}

the for loop will see 5 < 5, which is false, and thus the loop will not execute.
I think what you want to say is 
#include <stdio.h>

void printloop (int valx) {
    int x;
    for (x = 0; x < valx; x++) {
        printf("Value of x is: %d\n", x);
    }
}

int main() {
    printloop(5);
    return 0;
}

Which will output:
Value of x is: 0
Value of x is: 1
Value of x is: 2
Value of x is: 3
Value of x is: 4

I hope this makes sense, and keep up the good work!

