Java for loop [method]

hi all i want ask how can get out |pc| from for loop to anthor method like getPlayer or etc

        for (L2PcInstance pc : L2World.getInstance().getPlayers())
    {
        if (pc.isOnline() && ((pc.getClient() != null) && !pc.getClient().isDetached()))
        {
            Object[] rowData = new Object[]
            {
                pc.getAccountName(),
                pc.getId(),
                pc.getName(),
                pc.getLevel(),
                pc.getCurrentHp(),
                pc.getCurrentMp(),
                pc.getCurrentCp(),
                pc.getPvpKills(),
                pc.getPkKills(),
                pc.getBaseClass(),
                pc.getCreateDate()
            };
            model.addRow(rowData);
        }

    }

im try everything but not work can give me someone explame :( in my idea is like this

private L2PcInstance pc;
for (pc : L2World.getInstance().getPlayers())

public L2PcInstance getPlayer()
{
return pc;
}

thanks for your time :)

1 answer

  • answered 2017-06-17 19:26 GaurZilla

    You can use break if you want to move out of the for loop and make a call to any method as required.

        for (L2PcInstance pc : L2World.getInstance().getPlayers())
            {
                if (pc.isOnline() && ((pc.getClient() != null) && !pc.getClient().isDetached()))
                {
                    Object[] rowData = new Object[]
                    {
                        pc.getAccountName(),
                        pc.getId(),
                        pc.getName(),
                        pc.getLevel(),
                        pc.getCurrentHp(),
                        pc.getCurrentMp(),
                        pc.getCurrentCp(),
                        pc.getPvpKills(),
                        pc.getPkKills(),
                        pc.getBaseClass(),
                        pc.getCreateDate()
                    };
                    model.addRow(rowData);
                }
    break;
    
            }
    
    //call a new method here