1

How do I check if the current index is the last index in the table?

 2 years ago
source link: https://www.codesd.com/item/how-do-i-check-if-the-current-index-is-the-last-index-in-the-table.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How do I check if the current index is the last index in the table?

advertisements

How do I say?

for (i = 0; i < arraySize; i++)
{
    if (someArray[i + 1] !NULL)
    {
        //do this
    }
    else
    {
        //do something else
    }
}

In other words, I want to check if the current index is the last index in the array. The current code is my best guess but it isn't working.

EDIT: It is an integer array and i less than arraySize not 0

EDIT 2: The code inside my for loop is more complicated than the example above but I can't paste all the code as it is top secret atm. I have many nested if statements. if(i==arraySize-1) helped me to solve the problem. Thanks.


Following line will give you count of items in your array:

count  = sizeof (intMyArray)/sizeof(intMyArray[0]);

if you know arraySize then:

if(i==arraySize-1){
  //last element of array
}

Tags arrays

Related Articles

How do I check if the tables are equal in javascript?

Have a look at this code sample or go to the jsfiddle function printRelation(a, b, out) { var text; if (a === b) { text = "a === b"; } else if (a == b) { text = "a == b"; } else { text = "a != b"; } $('#' + out).text(text); }

How do I check whether the table has an object or not?

i want to check if the old array has object or not if the old array has the object it should show me the button if the oldArray has zero object the button should be hidden the code is given below thanks... -(void)viewWillAppear:(BOOL)animated { GET_D

Entity Framework - How do I check if the table exists?

I'm using the Entity Framework with Code First approach. The base class DbContext has functions to create and delete the database as well as to check for its existence. I want to check if a special table (entity) is existing or not. Is it possible wi

How do I check if the table already contains a certain value?

for some reasons the if statement is not being satisfied...on the first run of the loop it should have resulted to false since i have initiated an empty array which would then be populated once the if statement has been satisfied...please help...so f

How do I check if the user is in the admin part of Drupal?

How do i check if the current page is in the admin section of drupal?. I want to display a login form in some pages from the main menu but the login page is displayed in the block selection menu .Please suggest a solution ..For Drupal 7 you can use p

How do I check if the entry in an array has failed?

I'm doing a homework assignment and one function I need to write is a simple function that allows the user to input an int that will go into an array. One of the conditions though is to check if the input failed, and if it did, end the the program wi

Python - how to check if the table exists?

I'm using this function : def checker(name,s) MY_T = "SELECT count(*) FROM `"+session.SessionInfo.Name where EventName='"+name+"'" I want to check if the table exists, how can I do it ? I saw some examples using : XXXX.execute() w

How do I check if the result is a fraction

How can i check if the result of division of two numbers is fraction in visual basic here is what i need to do : Dim x As Integer = 12 Dim y As Integer = 5 If TypeOf x/y Is fraction Then ( do something ) End If Thanks in advanceUse Mod, which will re

How do I check if the data already exists in the combobox list?

How can I check if the data from cmbTypeYacht.text already exists in cmbTypeYacht.list? Here's what I've got: Dim TypeYacht As String 'Type of yacht input TypeYacht = cmbTypeYacht.Text If TypeYacht = ("cmbTypeYacht list") Then MsgBox "Type

How do I check if the cursor is on an item?

How can I check whether the cursor is over a div on the html page with JQuery/Javascript? I'm trying to get cursor coordinates to see if they are in the rectangle of my element. Maybe there are predefined methods? UPD, don't say anything about hover

How do I check if the date is in a list of date strings?

This will always print false. How can I check if the date is in the array and print the proper thing? dates = [ "2012-09-03", "2012-10-08", "2012-10-09", "2012-11-12", # .. more values snipped for brevity "2013

How do I check if the operating system is Sun Os or Unix or Solaris by bashrc

I want to know, how can we check in the bashrc file, what operating system is it?Use uname -a in your .bashrc file.

How do I check if the controls in a usercontrol contain a value?

How do I check whether the controls in a usercontrol contain any value? I have created a usercontrol called ctlCustomerAddress and I want to create an address record in the database if only I have the values in the textboxes.There are number of ways

How do I check if the JSON data is an object or set of objects?

I got server responsed JSON data: var data = SERVER_RESPONSE; this data could be an object {id: 12, name: John}, it could also be an array of objects [{id: 12, name: John}, {id: 22, name: OMG}] In Javascript, how can I check if the JSON data is one o

How do I check if the object is a DOM element?

This question already has an answer here: JavaScript isDOM - How do you check if a JavaScript Object is a DOM Object? 31 answers I have a function: function Check(o) { alert(/* o is a DOM element ? "true" : "false" */); } How can I che

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK