Abhay Jajodia's profileExpert

Abhay Jajodia

Answered 166 questions


About

Designer by day, web developer by night, and a full-time tech + gaming nerd in between. I'm always learning, always curious — chasing life's bonus levels, secret achievements, and power-ups like it's one big epic quest.

Answered by Abhay Jajodia
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Konstantin,

Yes, that condition creates an infinite loop — unless something inside the loop changes n to a negative value.

Let’s break it down:

  • n == 0 is true if n is exactly 0

  • n > 0 is true if n is positive

  • or means the loop will keep running as long as either of those is true

So basically, as long as n is zero or positive, the condition stays true, and the loop won’t stop. That makes it infinite — unless you manually change n inside the loop to something negative.

If your goal is to loop only while n is positive (and stop on zero or anything less), just write:

while n > 0:

Here’s a quick example:

n = float(input())
total = 0

while n > 0:
    total += n
    n = float(input())

print(total)

This will keep adding numbers until the user enters zero or a negative value.

If you have more questions, I am here to help.

Python
This question was asked as part of the Getting started with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Sanskriti,

Good observation — they’re both used in printf, but for different types of data.

  • %s is used to print a string (a sequence of characters ending with \0)

  • %c is used to print a single character

Here’s an example to make it clear:

char movie[] = "Snowpiercer";

// Prints the full string
printf("The full movie title is: %s\n", movie);

// Prints the 4th character (index 3)
printf("The fourth character is: %c\n", movie[3]);

So if you're printing the entire string, use %s.
If you're just printing one character from that string — like movie[3] — use %c.

If you have more questions, I am here to help.

C
This question was asked as part of the Learn C Programming course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Ramcharan,

Yes, you can use quotes around numbers in print(), but it changes what you're printing.

For example:

print(65.6)      # prints a number  
print("65.6")    # prints a string that looks like a number

Both will display 65.6, but the first one is a number, and the second is a string. Python treats them differently.

If you're just printing a value, both work. But if you want to use that value later for math, keep it as a number — don’t put it in quotes.

If you have more questions, I am here to help.

Python
This question was asked as part of the Getting started with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi George,

Good question — it confuses a lot of people at first.

When you use const with an array in JavaScript, you're saying the reference to the array can’t change — not the contents.

So this is allowed:

const fruits = ["Apple", "Banana", "Orange"];
fruits[1] = "Mango";  // ✅ You can update elements

But this is not allowed:

fruits = ["Grapes", "Pineapple"];  // ❌ Error: assignment to constant variable

So const just means you can’t assign a new array to that variable. You can still update, add, or remove elements from the original array.

If you have more questions, I am here to help.

JS
This question was asked as part of the Learn JavaScript Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Miki,

Great question — this is a common source of confusion in Java.

  • == checks if two variables point to the exact same object in memory. It doesn’t care about the content — just the reference.

  • .equals() checks if the content of two strings is the same, even if they’re different objects.

Example:

String a = new String("hello");
String b = new String("hello");

System.out.println(a == b);       // false — different objects
System.out.println(a.equals(b));  // true — same content

So whenever you want to compare the actual text in two strings, always use .equals().

If you have more questions, I am here to help.

Java
This question was asked as part of the Practice: Java Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Suteemon,

Great question — if you want to loop through each digit of an integer (not each number in a range), you can do it using division and modulus.

Here’s how you can do it in C:

int num = 1234;

while (num > 0) {
    int digit = num % 10;  // gets the last digit
    printf("%d\n", digit); // print or process the digit
    num = num / 10;        // remove the last digit
}

This will print:

4  
3  
2  
1

If you want the digits in the original order (1, 2, 3, 4), you can store them in an array or reverse them after collecting.

Let me know if you were asking about looping over a range of numbers instead — happy to help with that too.

If you have more questions, I am here to help.

C
This question was asked as part of the Practice: C Programming course.
Sarravanabavan Durairaj
PRO
last year
Sarravanabavancountry asked
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Sarravanabavan,

Good question — and it depends on the context.

In programming, indexing usually starts at 0. So in Python, for example:

matrix[0][0]  # first row, first column

But in mathematics, people usually count rows and columns starting from 1. So what programming calls "column 0", math might refer to as "column 1".

If you're learning from a math-based explanation or a textbook, it's normal to see columns numbered from 1. But if you're working with actual code, like Python or NumPy, indexing starts from 0.

So you're not doing anything wrong — it's just two different conventions.

If you have more questions, I am here to help.

Python
This question was asked as part of the Python Numpy for Data Science course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Julia,

Yes, that’s correct — if you don’t use a TCL command like COMMIT, your changes may not be saved permanently.

When you run SQL statements like INSERT, UPDATE, or DELETE, the changes happen in a temporary state called a transaction. They're not actually saved to the database until you explicitly commit them:

COMMIT;

If you don’t run COMMIT, and you close the connection or something goes wrong, those changes can be rolled back — meaning they’re lost.

You can also use:

  • ROLLBACK to undo changes

  • SAVEPOINT to mark specific points you might roll back to

So yes — using TCL commands like COMMIT is what finalizes your changes.

If you have more questions, I am here to help.

SQL
This question was asked as part of the Learn SQL Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi there! This is a great question and it's quite common for SQL learners to wonder about these nuances.

When writing a GRANT or REVOKE clause, the use of * and ALL TABLES might seem similar because they both refer to permissions applied to all tables within a database. However, depending on the SQL database system you are using, they might function slightly differently and could have different levels of compatibility and specificity.

- ***:** This is sometimes used as shorthand to represent operations across all tables in a database, but it heavily depends on the SQL database implementation you're dealing with. It's often more associated with selecting all columns in a SELECT statement than granting permissions. - **ALL TABLES:** This statement is very clear in intent, explicitly specifying that the action should apply to all tables. It's generally more explicit and more reliably interpreted across different SQL systems for data control operations.

Given this, ALL TABLES is the more universally accepted syntax for granting/revoking permissions across all tables in most SQL systems, which provides less ambiguity in cross-database usage.

Please, let me know if you have any further questions or if you'd like to see more examples. Hope this helps!

SQL
This question was asked as part of the Learn SQL Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi Michael,

Yes, they are! In Python, and, or, and not are called logical operators. They're used to work with boolean values — True and False — and control the flow of your program based on conditions.

Here’s what each one does:

  • and → returns True only if both conditions are true

  • or → returns True if at least one condition is true

  • not → flips the value: not True becomes False, and vice versa

Example:

age = 23
is_member = True

if age >= 18 and is_member:
    print("You can buy the offer!")
else:
    print("Sorry, offer not available.")

So yes — these are definitely operators, just like + or ==, but used for logic.

If you have more questions, I am here to help.

Python
This question was asked as part of the Getting started with Python course.